package org.javaweb.cms_web.util;


import org.javaweb.cms_web.model.LoginTicket;
import org.javaweb.cms_web.model.User;
import org.springframework.stereotype.Component;

@Component
public class HostHolder {
    private ThreadLocal<User> users = new ThreadLocal<>();
    private ThreadLocal<LoginTicket> loginTicketThreadLocal = new ThreadLocal<>();

    public void setUser(User user) {
        users.set(user);
    }

    public User getUser() {
        return users.get();
    }

    public void setLoginTicket(LoginTicket loginTicket) {
        loginTicketThreadLocal.set(loginTicket);
    }

    public LoginTicket getLoginTicket() {
        return loginTicketThreadLocal.get();
    }

    public void clear() {
        users.remove();
        loginTicketThreadLocal.remove();
    }
}
